﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV
{
    public partial class Form1 : Form
    {

        DataTable dt = new DataTable();
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string sql = "select * from song ";
            dt = DBHelper.Select(sql);
            dataGridView1.DataSource = dt;
        }

        private void SearchBt_Click(object sender, EventArgs e)
        {
            //string sql = string.Format("songType='{0}'",SelectTxt.Text);
            DataView dv = dt.DefaultView;
            dv.RowFilter= string.Format("songType='{0}'", SelectTxt.Text);
            dataGridView1.DataSource = dv;
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int rowindex = dataGridView1.CurrentRow.Index;
            
            string name = dataGridView1.Rows[rowindex].Cells["sName"].Value.ToString();
            string sql = string.Format("delete from Song where songName ='{0}'", name);
            bool re = DBHelper.Nonquery(sql);
            if (re==true)
            {
                MessageBox.Show("删除成功");
                
            }
            dataGridView1.Rows.RemoveAt(rowindex);

        }
    }
}
